<template>
<Modal
	v-model="show"
	title="发送站内信"
	:width="520"
	>
	<Form :model="info" :label-width="100" style="width: 100%" :rules="ruleValidate" ref="form">
		<FormItem label=" 发送对象：" prop="target_id">
			<user_filter v-model="info.target_id" style="width: 300px;"></user_filter>
		</FormItem>
		<FormItem label="标题：" prop="title">
			<Input v-model="info.title" placeholder="" style="width: 300px;"></Input>
		</FormItem>
		<FormItem label="内容：" prop="content">
			<Input type="textarea" v-model="info.content" placeholder="" style="width: 300px;" :rows="6"></Input>
			<p style="color: #999;">站内信标题不能超过20个字，内容不能超过100个字。</p>
		</FormItem>

		
	</Form>

	<div slot="footer" style="text-align: center;">
		<Button type="success" size="large" @click="handleSubmit('form')" >提交</Button>
	</div>
</Modal>

</template>

<script>
import user_filter from '@/themes/components/user_filter';

export default {
  name: 'station_info',
  components:{
	user_filter
  },
  data(){
	return {
		show:false,
		ruleValidate:{
			target_id:[
				{ required: true, message: '不能为空', trigger: 'blur' }
			],
			title: [
				{ required: true, message: '不能为空', trigger: 'blur' },
			],
			content: [
				{ required: true, message: '不能为空', trigger: 'blur' },
			],
		},
		def_info:{
			target_id:'',
			title:'',
			content:'',
		},
		info:{
			target_id:'',
			title:'',
			content:'',
		}
	};
  },
  props:['value','cinfo'],
  created(){
	this.show = this.value;
  },
  watch:{
	value(val){
		this.show = val;
	},
	show(val){
		this.$emit('input',val);
	},
	cinfo:{
		handler(val){
			
			if(typeof(val)!='object'){
				this.info = this._getData(this.def_info);
				return ;
			}
			
			for(var i in this.info){
				
				if(typeof(val[i])!='undefined'){
					this.info[i] = val[i];
				}
				else{
					this.info[i] = this.def_info[i];
				}
			}
			
			this.info.is_enable = parseInt(this.info.is_enable);
		},
		deep:true
	}
  },
  methods: {
	handleSubmit(name){
		var self = this;
		
		this.$refs[name].validate((valid) => {
			if (valid) {
				self.save();
			}
		})
	},
	save(){
		var self = this;
		var postdata = this.info;
		
		Whttp.load('System/Message/save',postdata, (res)=>{
			self.$Message.info('发送成功');
			self.show = false;
			self.$emit('success',res);
		});
	},
  }
}
</script>
<style scoped>

</style>